package org.red5.demos.ofla;

import org.apache.commons.lang3.StringUtils;
import org.red5.server.api.IConnection;
import org.red5.server.api.Red5;
import org.red5.server.api.scope.IScope;
import org.red5.server.api.stream.IStreamPlaybackSecurity;
import org.red5.util.JWTUtil;

public class NamePlaybackSecurity implements IStreamPlaybackSecurity {
	
	public boolean isPlaybackAllowed(IScope scope, String name, int start, int length, boolean flushPlaylist) {
		
        IConnection conn = Red5.getConnectionLocal();
        Object query = conn.getConnectParams().get("queryString");
        if(query == null){
        	return false;
        }
        String token = String.valueOf(query);
        if(!StringUtils.contains(token,"token=")){
        	return false;
        }
        String[] params = StringUtils.split(token,"=");
		String users = JWTUtil.getUserId(params[1]);
    	System.out.println(users);
    	return true;
	}
}